package com.clms.system.controller;

import com.clms.common.R;
import com.clms.system.myconfig.LogAnnotation;
import com.clms.system.pojo.entitry.SysRole;
import com.clms.system.pojo.vo.OnlyoneVo;
import com.clms.system.pojo.vo.RoleVo;
import com.clms.system.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;


/**
 * @program: clms-third
 * @description:
 * @author: 大鱼
 * @create: 2021-07-19 18:04
 **/
//@CrossOrigin
@RestController
@RequestMapping("system/role")
@Api(value = "操作角色的类")
public class RoleController {
    @Autowired
    RoleService roleService;

    @GetMapping("/showUserRole/{userid}")
    @ApiOperation(value = "根据id获取角色")
    @LogAnnotation(title = "获取id角色")
    public R getUserRole(@ApiParam(value = "获取id") @PathVariable("userid") Integer userid) {
        return roleService.getRole(userid);
    }
@LogAnnotation(title = "用户分角色")
    @GetMapping("/confirmsetrole")
    @ApiOperation("给账户设置角色")
    public R setrolebyuserid(@ApiParam("前台接受的角色数组") @RequestParam List<Integer> userRoleIds, @ApiParam("前台获取的用户id") @RequestParam Integer userId) {
        return roleService.confirmRole(userRoleIds, userId);
    }
@ApiOperation(value = "用户列表")
@LogAnnotation(title = "查询")
    @PostMapping("/initRoleTable/{currentPage}/{pageSize}")
    public R initRoleTable(@ApiParam("获取分页数") @PathVariable("currentPage") Integer currentPage, @ApiParam("封装前台搜索条件") @PathVariable("pageSize") Integer pageSize, @RequestBody RoleVo roleVo) {
        return roleService.initRoleTable(currentPage, pageSize, roleVo);
    }

    @ApiOperation(value = "更新角色表")
    @LogAnnotation(title = "更新")
    @GetMapping("updaterolestatus/{roleId}/{status}")
    public R updateRoleStatus(@PathVariable("roleId") Integer roleId, @PathVariable("status") Integer status) {

        return roleService.updateRoleStatus(roleId, status);
    }

    //删除角色
    @ApiOperation(value = "删除角色")
    @LogAnnotation(title = "删除")
    @DeleteMapping("deleterole/{roleId}")
    public R removerole(@PathVariable("roleId") Integer roleId) {
        return roleService.removerole(roleId);
    }

    //查找角色信息
    @ApiOperation(value = "更新角色表")
    @LogAnnotation(title = "更新")
    @PostMapping("addorudate")
    public R userAddOrUpdate(@RequestBody SysRole role) {
        return roleService.userAddOrUpdate(role);
    }
    @ApiOperation(value = "查询角色信息")
    @LogAnnotation(title = "查询角色信息")
    @GetMapping("getrolebyid/{roleId}")
    public R getUserInfo(@PathVariable("roleId") Integer roleId) {
        return roleService.getUserInfo(roleId);
    }
    @ApiOperation(value = "唯一性校验")
    @LogAnnotation(title = "唯一性校验")
    @PostMapping("onlyonecheck/byname")
    public R onlyOneCheckUrl(@RequestBody OnlyoneVo onlyoneVo) {
        return roleService.onlyOneCheckonlyOneCheckName(onlyoneVo);
    }
}
